<?php
/**
 * Project: AIGC
 * Author: moufer <moufer@163.com>
 * Date: 2024/7/6 12:02
 */

namespace module\ai\front\form;

use module\ai\library\channel\Factory;
use mof\enum\EnableEnum;
use mof\enum\StatusEnum;
use mof\front\Form;
use mof\Model;

class ChannelForm extends Form
{
    protected array $validate = [
        'param' => [
            'name', 'flag', 'status/d', 'config/a',
        ],
        'rule'  => [
            'flag|通道标识'   => 'require',
            'name|通道名称'   => 'require',
            'status|状态'     => 'require|in:0,1',
            'config|参数配置' => 'require|array',
        ],
    ];

    protected function elements(Model $model = null): array
    {
        return [
            [
                "label"    => "通道平台",
                "prop"     => "flag",
                "value"    => $model['flag'],
                "type"     => "select",
                "options"  => Factory::platformDict('config')->toElementData()->toSelectOptions(),
                "disabled" => true
            ],
            [
                "label" => "通道名称",
                "prop"  => "name",
                "value" => $model['name'] ?? ''
            ],
            [
                "label"   => "状态",
                "prop"    => "status",
                "type"    => "select",
                "value"   => $model['status'] ?? 1,
                "options" => EnableEnum::toDict()->toElementData()->toSelectOptions(),
            ],
            ...Factory::config($model['flag'])->getConfigForm($model)
        ];
    }

    protected function dialogAttrs(Model $model = null): array
    {
        return array_merge(parent::dialogAttrs($model), ['width' => 750]);
    }

}